package server;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;

import model.Message;

public class Client
{
	private static int lastId = 0;
	
	private String clientId;
	private Socket socket;
	private MessageReceiverThread messageReceiver;
	private ObjectOutputStream outputStream;

	public Client(final Socket socket) throws IOException
	{
		this.clientId = String.valueOf(lastId++);
		this.socket = socket;
		
		this.messageReceiver = new MessageReceiverThread(socket, this);
		this.messageReceiver.start();
		
		this.outputStream = new ObjectOutputStream(socket.getOutputStream());
	}

	public String getClientId()
	{
		return this.clientId;
	}
	
	public void setClientId(final String clientId)
	{
		this.clientId = clientId;
	}

	public Socket getSocket()
	{
		return this.socket;
	}

	public void sendMessage(final Message message)
	{
		try
		{
			this.outputStream.writeObject(message);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
}
